package com.steven.test.web.response;

import com.steven.test.enums.ResponseEnum;

/**
 * 返回结果统一处理
 *
 * @author qinxh
 * @date 2019/08/22
 */
public class ResponseData{

    private int code;

	private String message;

    private Object data;

	public ResponseData() {

	}

	public ResponseData(int code, String message) {

		super();
		this.code = code;
		this.message = message;
	}
	public ResponseData(int code, String message, Object data) {

		super();
		this.code = code;
		this.message = message;
		this.data = data;
	}
	
	/**
	 * 成功返回的结果
	 *
	 * @param data								返回数据
	 * @return ResponseData
	 */
	public static ResponseData ofSuccess(Object data){

		return new ResponseData(ResponseEnum.SUCCESS.getCode(),ResponseEnum.SUCCESS.getMessage(),data);
	}
	
	/**
	 * 根据枚举值返回结果
	 *
	 * @param responseEnum						枚举
	 * @return ResponseData
	 */
	public static ResponseData ofStatus(ResponseEnum responseEnum){

		return new ResponseData(responseEnum.getCode(),responseEnum.getMessage());
	}
	
	/**
	 * 自定义返回结果
	 *
	 * @param code								code
	 * @param message							信息
	 * @return ResponseData
	 */
	public static ResponseData ofMessage(int code,String message){

		return new ResponseData(code,message);
	}
	
	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public Object getData() {
		return data;
	}
	public void setData(Object data) {
		this.data = data;
	}
}